package com.dream.system.action;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.dream.common.JsonString;
import com.dream.common.Msg; 
import com.dream.common.SuperController;
import com.dream.model.SysUser;
import com.dream.model.Sys_Dict;
import com.dream.system.service.IDict;

@Controller
@RequestMapping("/edu/dictAction.do")
@SuppressWarnings("all") 
public class DictAction  extends SuperController
{
	@Autowired
	private IDict dictServiceImpl;
	/**
	 * 增加字典
	 * 
	 * @param model
	 * @param response
	 * @param request
	 * @throws IOException
	 * @throws Exception
	 */
	@RequestMapping(params = "method=addDict")
	public void addDict(Sys_Dict model, HttpServletResponse response, HttpServletRequest request) throws IOException
	{

	 
		int temp = this.dictServiceImpl.addDict(model);
		if (temp == 1)
		{
			Msg msg = this.getMsg("1", "操作成功!", null);
			response.getWriter().write(JSONObject.fromObject(msg).toString());
			response.getWriter().close();
			response.getWriter().flush();
		} else if (temp == 2)
		{
			Msg msg = this.getMsg("0", "操作失败!", null);
			response.getWriter().write(JSONObject.fromObject(msg).toString());
			response.getWriter().close();
			response.getWriter().flush();

		} else
		{
			Msg msg = this.getMsg("0", "操作失败!", null);
			response.getWriter().write(JSONObject.fromObject(msg).toString());
			response.getWriter().close();
			response.getWriter().flush();
		}

	}
	/**
	 * 查询字典
	 * 
	 * @param model
	 * @param response
	 * @param request
	 * @throws IOException
	 */
	@RequestMapping(params = "method=getDict")
	public void getDict(Sys_Dict model, HttpServletResponse response, HttpServletRequest request) throws IOException
	{
		Map map = this.dictServiceImpl.getDict(model);
		// Msg msg = this.getMsg("0", "操作成功!",
		// JSONObject.fromObject(map).toString());
		JsonConfig jsonConfig = new JsonConfig();
		//jsonConfig.setExcludes(JsonString.sys_user);
		response.getWriter().write(JSONArray.fromObject(map).toString());
		response.getWriter().close();
		response.getWriter().flush();

	}
	
	/**
	 * 查询字典
	 * 
	 * @param model
	 * @param response
	 * @param request
	 * @throws IOException
	 */
	@RequestMapping(params = "method=deletedict")
	public void deletedict(Sys_Dict model, HttpServletResponse response, HttpServletRequest request) throws IOException
	{
		String allId = request.getParameter("allId");
		String flag = request.getParameter("flag");
		int temp = this.dictServiceImpl.deletedict(allId, flag);
		if (temp == 1)
		{
			Msg msg = this.getMsg("1", "操作成功!", null);
			response.getWriter().write(JSONObject.fromObject(msg).toString());
			response.getWriter().close();
			response.getWriter().flush();
		} else
		{
			Msg msg = this.getMsg("0", "操作失败!", null);
			response.getWriter().write(JSONObject.fromObject(msg).toString());
			response.getWriter().close();
			response.getWriter().flush();
		}

	}
	
	
}
